#ifndef application_h
#define application_h

#include <Awesomium\WebCore.h>
#include <Awesomium\STLHelpers.h>
#include <Awesomium\BitmapSurface.h>
#include <TL\Map.h>
#include <TL\Queue_TS.h>
#include <TL\Runner.h>
#include <TL\SingleList.h>
#include <fstream>
#include <iostream>
#include <Windows.h>
#include "anchor.h"


using namespace Awesomium;


enum class PurchaseState {
    ReadyToPurchase,
    LoadingMarketPage,
    MarketPageLoaded,
    Waiting100msBeforeOpeningConfirmationDialog,
    ReadyToConfirmPurchase,
    Waiting100msBeforeClickingAwesomeButton,
    ReadyToClickAwesomeButton,
    Waiting5000msBeforeCheckingSuccessPurchase,
    CheckForSuccess,
    MoneyCheckFail,
    RemovingAnchor,
    RestartingAnchor
};


class Application {
private:
    WebCore *m_Core;
    WebSession *m_Session;
    WebView *m_Tab;

    Anchor *m_ActiveAnchor;
    TL::Queue_TS<Anchor *> m_AnchorQueue;
    TL::Map<Anchor *> m_Anchors;
    HANDLE m_DisplayThread;
    int m_ErrorCount;
    std::ofstream m_LogFile;
    PurchaseState m_PurchaseState;
    TL::Runner *m_Runner;
    DWORD m_TimeStamp;
    HWND m_Window;

private:
    Application(const Application &);
    Application &operator=(const Application &);

private:
    friend DWORD WINAPI display_thread(LPVOID thread_param);
    void on_cleanup();
    void on_close();
    void on_flash_window();
    void on_init();
    void on_process(TL::String input_str);
    void on_read_cookie_file();
    void on_start();
    void on_update();

public:
    Application(int &argc, char **argv);
    ~Application();

    int Execute();
};


TL::String getTimeString();

#endif
